package com.example.demo.common;

import com.example.demo.model.UserInfo;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: lishuo
 * Date: 2023-09-16
 * Time: 18:38
 */
public class SessionUtils {
    public static UserInfo getUser(HttpServletRequest request) {
        HttpSession session = request.getSession(false);
        if (session != null &&
                session.getAttribute(AppVar.SESSION_USERINFO_KEY) != null) {
            // 登录状态
            return (UserInfo) session.getAttribute(AppVar.SESSION_USERINFO_KEY);
        }
        return null;
    }
}
